package com.ruoyi.ftrl.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ftrl.domain.AvgTemperature;
import com.ruoyi.ftrl.service.IAvgTemperatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/avgtemperature")
public class AvgTemperatureController extends BaseController {
    @Autowired
    private IAvgTemperatureService avgTemperatureService;

    /**
     * 查询温度记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:avgtemperature:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(AvgTemperature avgTemperature) {
//        startPage();
        List<AvgTemperature> list = avgTemperatureService.selectAvgTemperatureList(avgTemperature);
        return getDataTable(list);
    }

    /**
     * 获取温度记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:avgtemperature:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(avgTemperatureService.selectAvgTemperatureById(id));
    }

    /**
     * 新增温度记录
     */
    @PreAuthorize("@ss.hasPermi('system:avgtemperature:add')")
    @Log(title = "平均温度记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AvgTemperature avgTemperature) {
        return toAjax(avgTemperatureService.insertAvgTemperature(avgTemperature));
    }

    /**
     * 修改温度记录
     */
    @PreAuthorize("@ss.hasPermi('system:avgtemperature:edit')")
    @Log(title = "平均温度记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AvgTemperature avgTemperature) {
        return toAjax(avgTemperatureService.updateAvgTemperature(avgTemperature));
    }

    /**
     * 删除温度记录
     */
    @PreAuthorize("@ss.hasPermi('system:avgtemperature:remove')")
    @Log(title = "平均温度记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(avgTemperatureService.deleteAvgTemperatureByIds(ids));
    }

    /**
     * 定时更新小区平均温度
     */
    @Anonymous
    @GetMapping("/all/list")
    public TableDataInfo allList() {
        List<AvgTemperature> list = avgTemperatureService.selectAvgTemperatureAllList();
        return getDataTable(list);
    }

}
